<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="关键词：">
          <el-input v-model="listPram.keyword" placeholder="关键词" clearable class="selWidth"/>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-form-item>
          <el-button size="mini" icon="el-icon-download" type="primary" @click="exportRecord">导出记录</el-button>
        </el-form-item>
        <el-form-item class="el-form-item-align-right">
          <el-button icon="el-icon-circle-plus" size="mini" type="primary" @click="openEdit()" v-if="userType === 6">
            添加
          </el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" size="mini"
                :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column align="center" label="ID" prop="id" width="60"></el-table-column>
        <el-table-column align="center" label="姓名" prop="name" width="70"/>
        <el-table-column align="center" label="性别" prop="sex" width="50"/>
        <el-table-column align="center" label="手机号" prop="phone" min-width="90"/>
        <el-table-column align="center" label="身份证号" prop="idCards" min-width="140"/>
        <el-table-column align="center" label="毕业院校" prop="school" min-width="70"/>
        <el-table-column align="center" label="毕业时间" prop="graduationTime" min-width="100"/>
        <el-table-column align="center" label="企业名称" prop="ename" min-width="170"/>
        <el-table-column align="center" label="纳税人识别号" prop="taxpayerIdentificationNumber" min-width="160"/>
        <el-table-column align="center" label="所在部门" prop="department" min-width="100"/>
        <el-table-column align="center" label="岗位名称" prop="postName" min-width="70"/>
        <el-table-column align="center" label="企业联系电话" prop="ephone" min-width="100"/>
        <el-table-column align="center" label="是否全勤" prop="fullAttendance" min-width="70"/>
        <el-table-column align="center" label="人社局审核状态" prop="fullAttendance" min-width="115">
          <template slot-scope="scope">
            <el-tag size="small" type="warning" v-if="scope.row.humanStatus === 0">待人社局审核</el-tag>
            <el-tag size="small" type="success" v-if="scope.row.humanStatus === 1 ">通过</el-tag>
            <el-tag size="small" type="danger" v-if="scope.row.humanStatus === 2">拒绝</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="银行审核状态" prop="fullAttendance" min-width="100">
          <template slot-scope="scope">
            <el-tag size="small" type="warning" v-if="scope.row.bankStatus === 0">待银行审核</el-tag>
            <el-tag size="small" type="success" v-if="scope.row.bankStatus === 1 ">通过</el-tag>
            <el-tag size="small" type="danger" v-if="scope.row.bankStatus === 2">拒绝</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="180" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(scope.row.id)"
                       v-if="userType === 6">编辑
            </el-button>
            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handlerDelete(scope.row.id)"
                       v-if="userType === 6">删除
            </el-button>
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openHumanEdit(scope.row)"
                       v-if="userType === 7">审核
            </el-button>
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openBankEdit(scope.row)"
                       v-if="userType === 8">审核
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="[20,40,60,80,100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
      :visible.sync="editDialog.show"
      :title="editDialog.id? '编辑':'新增'"
      destroy-on-close
      :close-on-click-modal="false"
      width="1200px"
      top="10px">
      <edit
        v-if="editDialog.show"
        :id="editDialog.id"
        @hideEditDialog="hideEditDialog"
        ref="editForm"
      />
    </el-dialog>
    <el-dialog
      :visible.sync="editHumanDialog.show"
      title="人社局审核"
      destroy-on-close
      :close-on-click-modal="false"
      width="1200px"
      top="10px">
      <human-examine
        v-if="editHumanDialog.show"
        :humanEdit="editHumanDialog.humanEdit"
        @hideHumanEditDialog="hideHumanEditDialog"
        ref="editForm"
      />
    </el-dialog>
    <el-dialog
      :visible.sync="editBankDialog.show"
      title="银行审核"
      destroy-on-close
      :close-on-click-modal="false"
      width="1200px"
      top="10px">
      <bank-examine
        v-if="editBankDialog.show"
        :bankEdit="editBankDialog.bankEdit"
        @hideBankEditDialog="hideBankEditDialog"
        ref="editForm"
      />
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit'
import {deleteRow, detail, exportEnterprise, getSelectEnterpriseById, list} from "@/api/enjoyEnterpriseSubsidies.js";
import {createFile, getForm} from "@/utils/utils";
import HumanExamine from "@/views/enjoyingEnterpriseSubsidies/human-examine.vue";
import BankExamine from "@/views/enjoyingEnterpriseSubsidies/bank-examine.vue";
import Cookies from "js-cookie";

export default {
  components: {BankExamine, HumanExamine, edit},
  data() {
    return {
      listData: {list: [], count: 0},
      listPram: {
        keyword: '',
        page: 1,
        limit: 20,
      },
      editDialog: {
        show: false,
        id: null
      },
      editHumanDialog: {
        show: false,
        humanEdit: null
      },
      editBankDialog: {
        show: false,
        bankEdit: null
      },
      tableLoading: false,
      userType: null,

    }
  },
  mounted() {
    this.userType = JSON.parse(Cookies.get("user"))?.userType || null;

    this.getList()
  },
  methods: {
    exportRecord() {
      this.$confirm('确定导出当前数据吗', '提示').then(() => {
        const loading = this.$loading({text: '处理中，请勿关闭页面'})
        exportEnterprise().then((res) => {
          if (!createFile(res, '享受补助学生名单')) {
            this.$message.error('未知的文件格式');
          }
        }).finally(() => {
          loading.close();
        })
      })
    },
    getList() {
      this.tableLoading = true
      list(this.listPram).then(res => {
        this.listData = res;
      }).finally(() => {
      })
      this.tableLoading = false;
    },
    openEdit(id = null) {
      this.editDialog.id = id;
      this.editDialog.show = true
    },
    openHumanEdit(humanEdit) {
      this.editHumanDialog.humanEdit = humanEdit;
      this.editHumanDialog.show = true
    },
    openBankEdit(bankEdit) {
      this.editBankDialog.bankEdit = bankEdit;
      this.editBankDialog.show = true
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading = this.$loading({text: '删除中', background: 'rgba(255,255,255,.5)'})
        deleteRow(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(() => {
          loading.close()
        })
      })
    },
    hideEditDialog() {
      this.editDialog.show = false
      this.getList()
    },
    hideHumanEditDialog() {
      this.editHumanDialog.show = false
      this.getList()
    },
    hideBankEditDialog() {
      this.editBankDialog.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery() {
      this.listPram.keyword = '';
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
